package com.marvin.spring.intercept.learning.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 * @ClassName: TimeFilter
 * @Description:
 * @Author Marvin
 * @Date 2019-05-22 19:28
 */
@Slf4j
public class TimeFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("Filter： -->Time Filter init");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("Filter： -->Time Filter start");
        long start = new Date().getTime();
        filterChain.doFilter(servletRequest, servletResponse);
        log.info("Filter： -->Time Filter finish, used time:" + (new Date().getTime() - start));
    }

    @Override
    public void destroy() {
        log.info("Filter： -->Time Filter destroy");
    }
}
